package com.chzu.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chzu.mapper.SysMenuMapper;
import com.chzu.pojo.SysMenu;
import com.chzu.result.JsonResult;
import com.chzu.result.PageResult;
import com.chzu.result.QueryInfo;
import com.chzu.service.SysMenuService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author lz
 * @Version 1.0
 * @Company 滁州大健康与养老产业研究院
 * @ClassName SysMenuServiceImpl
 * @Description TODO
 * @Date 2022/01/27 15:06
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
    @Resource
    private SysMenuMapper menuMapper;

    /**
     *  分页插叙你
     * @param queryInfo 页码、大小、查询内容
     * @return
     */
    @Override
    public JsonResult<Object> findMenu(QueryInfo queryInfo) {
        PageHelper.startPage(queryInfo.getPageNumber(), queryInfo.getPageSize());
        Page<SysMenu> page = menuMapper.findMenu(queryInfo.getQueryString());
        long total = page.getTotal();
        List<SysMenu> result = page.getResult();
        return PageResult.pageResult(result, total);
    }

    /**
     *  添加菜单信息
     * @param menu 菜单信息
     * @return
     */
    @Override
    public JsonResult<Object> insertMenu(SysMenu menu) {
        menu.setPath(menu.getPath().trim());
        menu.setComponent(menu.getComponent().trim());
        menuMapper.insertMenu(menu);
        return JsonResult.ok("添加菜单信息成功");
    }

    /**
     *
     * @param id
     * @return 菜单id
     */
    @Override
    public JsonResult<Object> deleteMenu(Integer id) {
        menuMapper.deleteMenu(id);
        return JsonResult.ok("删除菜单信息成功");
    }

    /**
     *  修改菜单信息
     * @param menu 菜单信息
     * @return
     */
    @Override
    public JsonResult<Object> updateMenu(SysMenu menu) {
        menuMapper.updateMenu(menu);
        return JsonResult.ok("修改菜单信息成功");
    }

    /**
     * 查询所有父级菜单
     * @return
     */
    @Override
    public JsonResult<Object> findParent() {
        return JsonResult.ok(menuMapper.findParent());
    }
}
